﻿

app.controller('HomeController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;

    function ControlCenter(type) {
        $scope.Type_1 = false;
        $scope.Type_2 = false;
        $scope.Type_3 = false;
        $scope.Type_4 = false;
        $scope.Type_5 = false;
        $scope.Type_6 = false;
        $scope.Type_7 = false;
        $scope.Type_8 = false;
        $scope.Type_9 = false;
        if (type == 1) {
            $scope.Type_1 = true;
        }
        if (type == 2) {
            $scope.Type_2 = true;
        }
        if (type == 3) {
            $scope.Type_3 = true;
        }
        if (type == 4) {
            $scope.Type_4 = true;
        }
        if (type == 5) {
            $scope.Type_5 = true;
        }
        if (type == 6) {
            $scope.Type_6 = true;
        }
        if (type == 7) {
            $scope.Type_7 = true;
        }
        if (type == 8) {
            $scope.Type_8 = true;
        }
        if (type == 9) {
            $scope.Type_9 = true;
        }
    }
    
    $scope.GetLocationList = function (id, type) {
        ControlCenter(type);
        $scope.LocationList = [];
        $scope.FactoryArea = id;
        $scope.Type = type;
        $http({
            method: 'POST',
            url: '../Home/GetLocationList',
            data: { 'FactoryAreaId': id, 'Type': type }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.LocationList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.ShowBuildingStruct = function (src, model) {
        $('#structview').addClass('open');
        $("#location_map").attr("src", src);
        $scope.CurrentBuilding = model;
    }

    $scope.doMapMouse = function (type, index) {
        if ($scope.LastId != undefined) {
            var last = document.getElementById($scope.LastId);
            if (last != null) last.style = "display:none";
        }
        $scope.LastId = type + index;
        var id = type + index;
        var detail = document.getElementById(id);
        detail.style = "display:inline";
    }

    $scope.MouseLeave = function (type, index) {
        var id = type + index;
        var detail = document.getElementById(id);
        if (detail != null) {
            detail.style = "display:none";
        }
    }

});

